<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
	<div class="panel panel">
	<div class="panel-body pan" style="height: 550px; overflow: auto;">
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">中文名称
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameZh" type="text" onchange="chinese_spell(this.value)" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div  class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">英文名称
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameEn" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">图标（logo）
					<!-- <span class='require'>*</span> --></label>
				<div class="col-md-9">
					<div>
						<input id="iconImg" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">显示位置<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="showLocation" class="form-control">
							<option value="0">头部</option>
							<option value="1">底部</option>
							<option value="2">右侧</option>
							<option value="3">都显示</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">父节点 
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="mineParentName" type="text"  value="根节点" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="mineZTree()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="mineParentId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			<div id = "passwordParent" class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">排序
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="sorts" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">类型<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="types" class="form-control" onchange="checkType()">
							<option value="0">关联新闻栏目</option>
							<option value="1">关联知识库</option>
							<option value="2">关联知识导航页</option>
							<option value="3">外部链接</option>
							<option value="4">关联站内链接</option>
						</select>
					</div>
				</div>
			</div>
			<div id = "relevanceUrlParent"  class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">外部链接URL
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="relevanceUrl" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
			<div id = "relevanceClassesParent" class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">关联知识库<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="relevanceClasses" class="form-control">
							
						</select>
					</div>
				</div>
			</div>
			<div id = "categoryParent" class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">关联新闻栏目
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="categoryNameZh" type="text"  value="根节点" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="categoryZTree()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="categoryId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			<div id = "relevancePageUrlParent" class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">关联站内链接URL
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="relevancePageUrl" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div  class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">权限用户
					<!-- <span class='require' id="yonghu">*</span> --> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="permissionsZh" type="text"  value="*" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="findMember()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="permissionsId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">状态<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">页面打开方式<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="openWith" class="form-control">
							<option value="0">本页面</option>
							<option value="1">新页面</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		</div>
	</div>
</div>
<?} ?>
<script>
	var index1 = window.parent.getlay();
	/* var _editor; */
	var classesIds = "";
	$(function() {
		showClass();
		if (index1 != 0) {
			$.ajax({
			type : "post",
			url : "findCmsNavbarById.do",
			data : {
				"id":index1
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				if(data.msg == "OK"){
					$("#nameZh").val(data.data.nameZh);
					$("#nameEn").val(data.data.nameEn);
					$('#nameEn').attr("disabled",true);
					$("#iconImg").val(data.data.iconImg);
					$("#showLocation").val(data.data.showLocation);
					$("#mineParentId").val(data.tree.parentId);
					$("#mineParentName").val(data.tree.parentName);
					$("#sorts").val(data.data.sort);
					$("#types").val(data.data.type);
					$("#permissionsId").val(data.tree.permissionsId);
					$("#permissionsZh").val(data.tree.permissionsName);
					$("#openWith").val(data.data.openWith);
					if(data.data.type == 0){
						$("#categoryParent").show();
						$("#categoryId").val(data.tree.categoryId);
					$("#categoryNameZh").val(data.tree.categoryName);
					}else if(data.data.type == 1 || data.data.type == 2){
						$("#relevanceClassesParent").show();
						$("#relevanceClasses").val(data.data.relevanceClassesEn);
					}else if(data.data.type == 3){
						$("#relevanceUrlParent").show();
						$("#relevanceUrl").val(data.data.relevanceUrl);
					}else if(data.data.type == 4){
						$("#relevancePageUrlParent").show();
						$("#relevancePageUrl").val(data.data.relevancePageUrl);
					}
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				
			}
		});
		
		}else{
			checkType()
		}
		 
	});
	
	function save() {
		/* var saveText = UE.getEditor('containerText'); */
		//获取html内容
		/* var ueditortext = saveText.getContent(); */
		var regexSort = /^[0-9]*$/;
		if($.trim($("#nameZh").val()).length<1) {
    	        	alert('中文名称不能为空');
    	        	return null;
    	    }
		 if($.trim($("#nameEn").val()).length<1) {
    	        	alert('英文名称不能为空');
    	        	return null;
    	    }
		 if($.trim($("#sorts").val()).length<1) {
    	        	alert('排序不能为空！');
    	        	return null;
    	    }
    	    
    	if(!regexSort.test($("#sorts").val())){
    		alert('排序请输入数字！');
	        return null;
    	}
   	    if($("#types").val() == 3){
   	    	if($.trim($("#relevanceUrl").val()).length<1) {
   	        	alert('外部链接URL不能为空！');
   	        	return null;
   	    	}
   	    }
		 if($("#types").val() == 4){
		 	if($.trim($("#relevancePageUrl").val()).length<1) {
    	        	alert('关联站内链接URL不能为空！');
    	        	return null;
    	    }
		 }
		 
		$.ajax({
			type : "post",
			url : "cmsNavbarAddUpdate.do",
			data : {
				"nameZh":$("#nameZh").val(),
				"nameEn":$("#nameEn").val(),
				"iconImg":$("#iconImg").val(),
				"showLocation":$("#showLocation").val(),
				"mineParentId":$("#mineParentId").val(),
				"sorts":$("#sorts").val(),
				"status":$("#status").val(),
				"id":index1,
				"types":$("#types").val(),
				"relevanceUrl":$("#relevanceUrl").val(),
				"relevanceClasses":$("#relevanceClasses").val(),
				"categoryId":$("#categoryId").val(),
				"relevancePageUrl":$("#relevancePageUrl").val(),
				"permissionsId":$("#permissionsZh").val(),
				"openWith":$("#openWith").val()
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				if(data.msg == "OK"){
					var index = parent.layer.getFrameIndex(window.name);
					window.parent.demo(1);
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				
			}
		});
	}
	
	/*关联知识库*/
	function showClass(){
		$.ajax({
			type : "post",
			url : "selectClass.do",
			data : {
			},
			dataType : "json",
			success : function(data) {
				if(data.msg == "OK"){
					var content = "";
					$.each(data.data,function(k,v){
						content += '<option value="'+v.nameEn+'">'+v.nameZh+'</option>'
					})
					$("#relevanceClasses").html(content);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	/*权限用户*/
	function findMember(){
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"授权用户列表",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["cms-navbar-user.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	/*关联新闻栏目*/
	function categoryZTree() {
		parent.layer.open({
			type : 2,
			area : [ '560px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title : "选择关联新闻栏目",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [
					"cms-navbar-category-ztree.html?winName="+ window.name, 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	
	/*父节点树*/
	
	function mineZTree() {
		parent.layer.open({
			type : 2,
			area : [ '560px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title : "选择父节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [
					"cms-navbar-mine-ztree.html?winName="+ window.name, 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	
	/*汉字转化拼音*/
	
   function chinese_spell(spell){
	  /* if(objectPropertyid == 0){ */
	  	/* if(cop == 00){ */
	  	var reg = "[A-Z]+";     
        var r = spell.match(reg);
	        if(r == null){
				$.ajax({
					type : "post",
					url : "pinYin.do",
					data : {
						"pinYin" : spell,
					},
					async : false,
					dataType : "json",
					success : function(data) {
						/* if(data[0].length > 20){ */
							$("#nameEn").val(data);
						/* } */
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}else{
				alert("英文名不可存在大写，请手动输入英文名");
				$("#analysisEnname").val("");
			}
		/* } */
		/* } */
	}
	
	function checkType(){
		if($("#types").val() == 0){
			$("#relevanceUrlParent").hide();
			$("#relevanceClassesParent").hide();
			$("#categoryParent").show();
			$("#relevancePageUrlParent").hide();
		}
		if($("#types").val() == 1 || $("#types").val() == 2){
			$("#relevanceUrlParent").hide();
			$("#relevanceClassesParent").show();
			$("#categoryParent").hide();
			$("#relevancePageUrlParent").hide();
			showClass();
		}
		if($("#types").val() == 3){
			$("#relevanceUrlParent").show();
			$("#relevanceClassesParent").hide();
			$("#categoryParent").hide();
			$("#relevancePageUrlParent").hide();
		}
		if($("#types").val() == 4){
			$("#relevanceUrlParent").hide();
			$("#relevanceClassesParent").hide();
			$("#categoryParent").hide();
			$("#relevancePageUrlParent").show();
		}
	}
</script>